package com.ruoyi.charge.controller;

import java.util.List;
import java.util.Arrays;

import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.charge.vo.CashOutVo;
import com.ruoyi.charge.bo.CashOutQueryBo;
import com.ruoyi.charge.bo.CashOutAddBo;
import com.ruoyi.charge.bo.CashOutEditBo;
import com.ruoyi.charge.service.ICashOutService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 提现审批Controller
 *
 * @author fanqie
 * @date 2021-10-25
 */
@Api(value = "提现审批控制器", tags = {"提现审批管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/charge/cash_out")
public class CashOutController extends BaseController {

    private final ICashOutService iCashOutService;

    /**
     * 查询提现审批列表
     */
    @ApiOperation("查询提现审批列表")
    @GetMapping("/list")
    public TableDataInfo<CashOutVo> list(CashOutQueryBo bo) {
        startPage();
        List<CashOutVo> list = iCashOutService.queryList(bo);
        return getDataTable(list);
    }


    /**
     * 获取提现审批详细信息
     */
    @ApiOperation("获取提现审批详细信息")
    @GetMapping("/{id}")
    public AjaxResult<CashOutVo> getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(iCashOutService.queryById(id));
    }

    /**
     * 新增提现审批
     */
    @ApiOperation("新增提现审批")
    @Log(title = "提现审批", businessType = BusinessType.INSERT)
    @PostMapping()
    public AjaxResult<Void> add(@RequestBody CashOutAddBo bo) {
        return toAjax(iCashOutService.insertByAddBo(bo) ? 1 : 0);
    }

    /**
     * 修改提现审批
     */
    @ApiOperation("修改提现审批")
    @Log(title = "提现审批", businessType = BusinessType.UPDATE)
    @PutMapping()
    public AjaxResult<Void> edit(@RequestBody CashOutEditBo bo) {
        return toAjax(iCashOutService.updateByEditBo(bo) ? 1 : 0);
    }

    /**
     * 删除提现审批
     */
    @ApiOperation("删除提现审批")
    @Log(title = "提现审批", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult<Void> remove(@PathVariable Long[] ids) {
        return toAjax(iCashOutService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }
}
